/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.reportinventorysummary.service
 * FILE    NAME: ReportInventorySummaryDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.reportinventorysummary.service;

import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSON;
import com.hero.common.web.excel.util.ExcelExport;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.PageResult;
import com.hero.core.entity.ResponseEntity;
import com.hero.core.exception.AbstractGenericException;
import com.hero.core.util.DateUtils;
import com.hero.core.util.StringUtils;
import com.hero.core.util.ValidationUtil;
import com.jodinfo.outmirror.api.ReportConstant;
import com.jodinfo.outmirror.api.Dymcform.service.DymcformQueryService;
import com.jodinfo.outmirror.api.inventorystkflow.entity.InventoryStkFlowEntity;
import com.jodinfo.outmirror.api.inventorystkflow.service.InventoryStkFlowQueryService;
import com.jodinfo.outmirror.api.loseform.entity.LoseformEntity;
import com.jodinfo.outmirror.api.loseform.service.LoseformQueryService;
import com.jodinfo.outmirror.api.loseformbarcode.entity.LoseformBarcodeEntity;
import com.jodinfo.outmirror.api.loseformbarcode.service.LoseformBarcodeQueryService;
import com.jodinfo.outmirror.api.org.entity.OrgEntity;
import com.jodinfo.outmirror.api.org.service.OrgQueryService;
import com.jodinfo.outmirror.api.reportinventoryanalyze.service.OfficeEntity;
import com.jodinfo.outmirror.api.reportinventorysummary.entity.ReportInventorySummaryEntity;
import com.jodinfo.outmirror.api.workflow.entity.UserTask;
import com.jodinfo.outmirror.api.workflow.service.ActivitiTaskQueryService;
import com.taobao.ad.easyschedule.dataobject.JobData;
import com.taobao.ad.easyschedule.dataobject.JobResult;

@Service(value="reportInventorySummaryBizService")
public class ReportInventorySummaryBizServiceImpl implements ReportInventorySummaryBizService {
    private static final Logger logger = LoggerFactory.getLogger(ReportInventorySummaryBizServiceImpl.class);
 	
 	@Resource(name="reportInventorySummaryDmlService")
	private ReportInventorySummaryDmlService ReportInventorySummaryDmlService;
	@Resource(name="reportInventorySummaryQueryService")
	private ReportInventorySummaryQueryService ReportInventorySummaryQueryService;
	@Resource(name="activitiTaskQueryService")
	private ActivitiTaskQueryService activitiTaskQueryService;
	@Resource(name="inventoryStkFlowQueryService")
	private InventoryStkFlowQueryService inventoryStkFlowQueryService;
	@Resource(name="dymcformQueryService")
	private DymcformQueryService dymcformQueryService;
	@Resource(name="orgQueryService")
	private OrgQueryService orgQueryService;
	@Resource(name="loseformQueryService")
	private LoseformQueryService loseformQueryService; 
	@Resource(name="loseformBarcodeQueryService")
	private LoseformBarcodeQueryService loseformBarcodeQueryService; 
	
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryBizService#addReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param ReportInventorySummaryEntity ReportInventorySummaryEntity
	 * @return int
	 */
	public ResponseEntity addReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity) {
			ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
			  	 int i =  ReportInventorySummaryDmlService.addReportInventorySummary(ReportInventorySummaryEntity);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryBizService#updateReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param ReportInventorySummaryEntity ReportInventorySummaryEntity
	 * @return ResponseEntity
	 */
	public ResponseEntity updateReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
				int i = ReportInventorySummaryDmlService.updateReportInventorySummary(ReportInventorySummaryEntity);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryBizService#queryAllReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param ReportInventorySummaryEntity ReportInventorySummaryEntity
	 * @return String
	 */
	public String queryAllReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity) {
		return JSON.toJSONString(ReportInventorySummaryQueryService.queryAllReportInventorySummary(ReportInventorySummaryEntity));
	} 
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryBizService#queryAllReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param ReportInventorySummaryEntity ReportInventorySummaryEntity
	 * @return PageResult
	 */
	public String queryListForPageReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity) {
		return new PageResult( ReportInventorySummaryQueryService.queryListForPageReportInventorySummary(ReportInventorySummaryEntity), ReportInventorySummaryQueryService.queryCountReportInventorySummary(ReportInventorySummaryEntity)).toString();
	} 
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryQueryService#queryById(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param BigInteger id
	 * @return
	 */
	public ReportInventorySummaryEntity queryById(BigInteger id) {
		return ReportInventorySummaryQueryService.queryById(id);
	}
	
	public void exportReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity, HttpServletResponse response) {
		List<ReportInventorySummaryEntity> exportList = null;
		String ids = ReportInventorySummaryEntity.getIds();
		if (ValidationUtil.isNullOrEmptyString(ids)) {
			exportList =ReportInventorySummaryQueryService.queryAllReportInventorySummary(ReportInventorySummaryEntity);
		} else {
			String[] idArray = ids.split(",");
			List<BigInteger> idList = new ArrayList<BigInteger>();
			for(String id : idArray) {
				idList.add(new BigInteger(id));
			}
			exportList = ReportInventorySummaryQueryService.queryByIds(idList);
			// 将字典中的code转换为name
		   //convertCodeToName(exportList);
		}
		ExcelExport.exportExcel(exportList, "ReportInventorySummaryEntityExcel", "ReportInventorySummaryEntity信息", response);
	}
	
	/** 
	 * 批量删除 数据处理
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryQueryService#queryById(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param BigInteger id
	 * @return
	 */
	public ResponseEntity batchDelReportInventorySummary(ReportInventorySummaryEntity ReportInventorySummaryEntity) {
		String ids = ReportInventorySummaryEntity.getIds();
		String[] idArray = ids.split(",");
		List<ReportInventorySummaryEntity> ReportInventorySummaryEntityList = new ArrayList<ReportInventorySummaryEntity>();
		for(String id : idArray) {
			ReportInventorySummaryEntity ReportInventorySummaryModel = new ReportInventorySummaryEntity();
			ReportInventorySummaryModel.setId(new BigInteger(id));
//			ReportInventorySummaryModel.setLastUpdateUsrName(UserContext.getUser().getName());
//			ReportInventorySummaryModel.setLastUpdateTime(DateUtils.getCurrentTime());
//			ReportInventorySummaryModel.setIsDel(SysConstant.IS_DEL_Y);
			ReportInventorySummaryModel.setUpdateTime(DateUtils.getCurrentTime());
			ReportInventorySummaryEntityList.add(ReportInventorySummaryModel);
		}
		return batchUpdateReportInventorySummary(ReportInventorySummaryEntityList);
	}
	
	/**
	 * 执行批量删除操作
	 * @author weiwei
	 * @date 2017年3月13日 上午11:40:31
	 * @param ReportInventorySummaryList
	 * @return
	 */
	public ResponseEntity batchUpdateReportInventorySummary(List<ReportInventorySummaryEntity> ReportInventorySummaryList) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
				int i = ReportInventorySummaryDmlService.batchUpdateReportInventorySummary(ReportInventorySummaryList);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	
	/**
	 * 
	 * @author weiwei
	 * @date 2017年3月13日 上午10:24:53
	 * @see  com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryQueryService#queryById(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param map
	 * @param excelimportcontext
	 * @param s
	 * @return
	 * @throws Exception
	 */
	/*public List<BigInteger> insertData(Map<Integer, List<Object>> map,ExcelImportContext excelimportcontext, String s) throws Exception {
		String usrName = UserContext.getUser().getName();//数据创建人
		String creatTime = DateUtils.getCurrentTime();
		List<ReportInventorySummaryEntity> ReportInventorySummaryList = validateReportInventorySummaryData(map, excelimportcontext,usrName,creatTime);
		if (!excelimportcontext.hasError() && ReportInventorySummaryList.size() > 0) {
			batchAddReportInventorySummary(ReportInventorySummaryList);
		}
		return null;
	}*/
	
	/**
	 * 
	 * TODO 验证数据 处理业务数据
	 * @author weiwei
	 * @date 2017年3月13日 上午9:33:30
	 * @see  com.jodinfo.outmirror.implementation.reportinventorysummary.ReportInventorySummaryQueryService#queryById(ReportInventorySummaryEntity ReportInventorySummaryEntity)
	 * @param ReportInventorySummaryList
	 * @return
	 */
	/*public List<ReportInventorySummaryEntity> validateReportInventorySummaryData(Map<Integer, List<Object>> map,ExcelImportContext excelimportcontext,String usrName,String creatTime) {
		ExcelImportContext.DataError errorMsg = null;
		List<ReportInventorySummaryEntity> ReportInventorySummaryList = new ArrayList<ReportInventorySummaryEntity>();
		for (Map.Entry<Integer, List<Object>> entity : map.entrySet()) {
			List<Object> excelModelList = entity.getValue();
			if (ValidationUtil.isNullOrEmptyCollection(excelModelList)) {
		//		errorMsg = excelimportcontext.new DataError(InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET,
		//				"导入数据为空！",InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET);
		//		excelimportcontext.push(errorMsg);
			}else{
				//TODO 验证对应数据
				for (int i =0;i<excelModelList.size();i++) {
					ReportInventorySummaryEntity ReportInventorySummaryModel = (ReportInventorySummaryEntity) excelModelList.get(i);
	 				if (checkDataByEntityModel(shShopModel, excelimportcontext, i)) {
						break;
					}
					//TODO 实体对象加入对应参数值 
					ReportInventorySummaryModel = setEntityData(ReportInventorySummaryModel,usrName, creatTime);
					ReportInventorySummaryList.add(ReportInventorySummaryModel);
				}
			}
		}
		return ReportInventorySummaryList;
	}*/
	
	/**
	 * 
	 * 单个导入实体数据校验 有错误返回true
	 * @author weiwei
	 * @date 2017年3月28日 下午3:59:17
	 * @param eqEquipmentModel
	 * @param excelimportcontext
	 * @param i
	 * @return
	 */
	/*public boolean checkDataByEntityModel(ReportInventorySummaryEntity ReportInventorySummaryModel,ExcelImportContext excelimportcontext,int i) {
		if (checkSingleData(excelimportcontext, ReportInventorySummaryModel.getIsDel, i+2,"错误信息") 
			//	|| checkSingleData(excelimportcontext, ReportInventorySummaryModel.getEquipmentColor(), i+2, "颜色为空！")
			//	||checkSingleData(excelimportcontext, ReportInventorySummaryModel.getEquipmentModel(), i+2, "型号为空！")
				) {
			return true;
		}else{
			return false;
		}
	}*/
	
	/**
	 * 
	 * 设置报错信息
	 * @author weiwei
	 * @date 2017年3月22日 下午5:17:37
	 * @param excelimportcontext
	 * @param rowNumId
	 * @param errorMessage
	 * @param sheetNumId 现在只有一个sheet 就不传值 默认值即可
	 */
	/*public boolean checkSingleData(ExcelImportContext excelimportcontext,String checkVal,int rowNumId,String errorMessage) {
		boolean flag = false;
		ExcelImportContext.DataError errorMsg = null;
		if (ValidationUtil.isNullOrEmptyString(checkVal)) {
			errorMsg = excelimportcontext.new DataError(rowNumId,errorMessage,InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET);
			excelimportcontext.push(errorMsg);
			flag = true;
		}
		return flag;
	}*/
	
	/**
	 * 
	 * 导入单个实体添加统一导入人及导入时间
	 * @author zhuxiaoliu
	 * @date 2017年3月28日 下午4:05:15
	 * @param eqEquipmentModel
	 * @param usrName
	 * @param creatTime
	 * @return
	 */
	/*public ReportInventorySummaryEntity setEntityData(ReportInventorySummaryEntity ReportInventorySummaryModel,String usrName,String creatTime) {
		
		//ReportInventorySummaryModel.setEquipmentId(InventoryConstantUtil.EQ_EQUIPMENT_SEQUENCE);
		ReportInventorySummaryModel.setCreateTime(creatTime);
		ReportInventorySummaryModel.setCreateUsrName(usrName);
		ReportInventorySummaryModel.setLastUpdateUsrName(usrName);
		ReportInventorySummaryModel.setLastUpdateTime(creatTime);
		ReportInventorySummaryModel.setIsDel(SysConstant.IS_DEL_N);
		return ReportInventorySummaryModel;
	}*/
	
	
	/**
	 * 
	 * 执行批插入操作
	 * @author weiwei
	 * @date 2017年3月13日 上午11:37:14
	 * @param {moduleName}List
	 * @return
	 */
	public ResponseEntity batchAddReportInventorySummary(List<ReportInventorySummaryEntity> ReportInventorySummaryList) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
		try{
			int i = ReportInventorySummaryDmlService.batchAddReportInventorySummary(ReportInventorySummaryList);
			 rs.setMessage(i+"条记录插入操作成功");
		 }catch(AbstractGenericException e){
			logger.error(e.getFullMessage());
			rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
		}catch(Exception e){
			String errorMessage = StringUtils.toString(e);
			logger.error(errorMessage);
			rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
		}
		return rs;
	}
	public JobResult execute(JobData jobData) throws Exception {
		ResponseEntity rs = scanForm(null);
		JobResult jobResult = JobResult.succcessResult();
		jobResult.setResultMsg(rs.getMessage());
		
		return jobResult;
	}
	
	private ResponseEntity scanForm(String date){
		ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS,"操作成功");
	
		try{
		ReportInventorySummaryEntity reportInventorySummaryEntity = new ReportInventorySummaryEntity();
		OrgEntity orgEntity = new OrgEntity();
		List<OrgEntity> orgList = orgQueryService.queryAllOrg(orgEntity);
		// 安装单
		Map<String,ReportInventorySummaryEntity> summaryMap = getSummaryMap(orgList);
		reportInventorySummaryEntity.setUpdateTime(DateUtils.getCurrentTime().substring(0, 10));
		buildInstallData(summaryMap,orgList,date);
		//入库
		buildAccessStorage(summaryMap,orgList,date);
		// 维修
		Map<String,ReportInventorySummaryEntity> scrapSummary = buildRepairData(summaryMap,orgList,date);
		// 丢失单
		buildLoseData(summaryMap,orgList,date);
		// 报废单
		buildScrapData(summaryMap, scrapSummary,orgList,date);
		// 领用单
		buildUsageData(summaryMap, orgList,date);
		// 补充字段值
		List<ReportInventorySummaryEntity> reportInventorySummaryEntityList = setListItemValue(
				orgList, summaryMap,date);
		
		ReportInventorySummaryDmlService.batchAddReportInventorySummary(reportInventorySummaryEntityList);
	}catch(Exception e){
		logger.debug(StringUtils.toString(e));
		rs.setMessage(StringUtils.toString(e));
		rs.setStatus(SysConstant.FAIL);
	}
		return rs;
	}
	/**
	 * 对每条插入记录补充一些值
	 * @author cao.weiwei
	 * @date 2017年7月19日 下午5:03:37
	 * @param orgList
	 * @param summaryMap
	 * @return
	 */
	private List<ReportInventorySummaryEntity>  setListItemValue(
			List<OrgEntity> orgList,
			Map<String, ReportInventorySummaryEntity> summaryMap,
			String date) {
		String todayDate = DateUtils.getCurrentTime().substring(0,10);
		Date yesterD = DateUtils.getDatePlusDay(DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate), -1);
		String yester =  DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, yesterD);
		String updateTimeStr = null;
		boolean isToday = true;
		if(!StringUtils.isEmpty(date)){
			Date d = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, date);
			updateTimeStr = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, d);
			isToday = false;
		}
		
		List<ReportInventorySummaryEntity> reportInventorySummaryEntityList = new ArrayList<ReportInventorySummaryEntity>();
		for(Map.Entry<String, ReportInventorySummaryEntity> entry: summaryMap.entrySet()){
			ReportInventorySummaryEntity temp = entry.getValue();
			OfficeEntity ofe = getOfficeEntity(entry.getKey(), orgList);
			temp.setBranchOrgId(ofe.getBranchOrgId());
			temp.setBranchOrgName(ofe.getBranchOrgName());
			temp.setOfficeOrgId(ofe.getOfficeOrgId());
			temp.setOfficeOrgName(ofe.getOfficeOrgName());
			temp.setUpdateTime(yester);
			calcRingValue(yester, entry.getKey(), temp);
			calcRelativeValue(yester, entry.getKey(), temp);
			if(!isToday){
				temp.setUpdateTime(updateTimeStr);
			}
			reportInventorySummaryEntityList.add(temp);
		}
		return reportInventorySummaryEntityList;
	}
	
	/**
	 * 丢失数量合计
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午2:50:42
	 * @param summaryMap
	 * @param orgList
	 */
	private void buildLoseData(
			Map<String, ReportInventorySummaryEntity> summaryMap,
			List<OrgEntity> orgList,String date) {
		 List<LoseformEntity> loseList =  new ArrayList<LoseformEntity>();
		 if(StringUtils.isEmpty(date)){
			 loseList = queryYesterDayForm();
		 }else{
			 loseList = queryOneDayForm(date);
		 }
		 Map<String, List<LoseformEntity>>  orgMap = queryLoseFormListByOrg(loseList);
		buildLoseSumData(summaryMap, orgMap);
		
	}
	/**
	 * 查询某日已完成的遗失单
	 * @author cao.weiwei
	 * @date 2017年8月9日 上午11:51:26
	 * @return
	 */
	private List<LoseformEntity> queryOneDayForm(String date) {
		LoseformEntity loseform = new LoseformEntity();
		Date theDate = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, date);// 当天
		Date theDateAfter = DateUtils.getDatePlusDay(theDate, 1);
		loseform.setPassTimeStart(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, theDate));
		loseform.setPassTimeEnd(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, theDateAfter));
		loseform.setStatus("3"); // 审批通过
		List<LoseformEntity> list = loseformQueryService.queryAllLoseform(loseform);
		return list;
	}
	/**
	 * 设置丢失量子段数据
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午2:50:01
	 * @param summaryMap
	 * @param orgMap
	 */
	private void buildLoseSumData(
			Map<String, ReportInventorySummaryEntity> summaryMap,
			Map<String, List<LoseformEntity>> orgMap) {
		 for(Map.Entry<String,List<LoseformEntity>> entry: orgMap.entrySet()){
			 List<LoseformEntity> list = entry.getValue();
			 Integer sum = 0;	 
			 if(!CollectionUtils.isEmpty(list)){
				 for(LoseformEntity form: list){
					sum+= queryEqTypeSum(form);
				 }
			 }
			summaryMap.get(entry.getKey()).setSumLose(sum.toString());
		 }
	}
	/**
	 * 计算这个单子的设备数量
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午2:49:42
	 * @param form
	 * @return
	 */
	private Integer queryEqTypeSum(LoseformEntity form) {
		LoseformBarcodeEntity codeEntity = new LoseformBarcodeEntity();
		codeEntity.setWoNo(form.getWoNo());
		List<LoseformBarcodeEntity> list = loseformBarcodeQueryService.queryAllLoseformBarcode(codeEntity);
		Integer sum = 0;
		if(!CollectionUtils.isEmpty(list)){
			for(LoseformBarcodeEntity e: list){
				String eqNum = e.getEqNum();
				sum+= Integer.parseInt(eqNum);
			}
		}
		return sum;
	}
	
	/**
	 * 将丢失单根据组织机构分类放进 orgMap
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午2:49:03
	 * @param loseList
	 * @return
	 */
	private Map<String, List<LoseformEntity>> queryLoseFormListByOrg(
			List<LoseformEntity> loseList) {
		Map<String,List<LoseformEntity>> orgKeyMap = new HashMap<String,List<LoseformEntity>>();
		buildOrgLoseformEntity(orgKeyMap);
		if(!CollectionUtils.isEmpty(loseList)){
			for(LoseformEntity lose: loseList){
				String orgId = lose.getOrgId();
				orgKeyMap.get(orgId).add(lose);
			}
		}
		return orgKeyMap;
	}
	/**
	 * 对每个组织机构创建一个List, 存放这个组织机构下面的单子
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午2:48:18
	 * @param orgMap
	 */
	private void buildOrgLoseformEntity(Map<String,List<LoseformEntity>> orgMap){
		List<OrgEntity> orgList = orgQueryService.queryAllOrg(new OrgEntity());
		for(OrgEntity orgEntity: orgList){
			orgMap.put(orgEntity.getOrgId(), new ArrayList<LoseformEntity>());
		}
	}
	/**
	 * 查询昨日的丢失单
	 * @author cao.weiwei
	 * @date 2017年7月14日 下午2:36:17
	 * @return
	 */
	private List<LoseformEntity> queryYesterDayForm() {
		LoseformEntity loseform = new LoseformEntity();
		Date todayDate = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, DateUtils.getCurrentTime().substring(0, 10));
		Date yesterDate = DateUtils.getDatePlusDay(todayDate, -1);
		loseform.setPassTimeStart(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, yesterDate));
		loseform.setPassTimeEnd(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate));
		loseform.setStatus("3"); // 审批通过
		List<LoseformEntity> list = loseformQueryService.queryAllLoseform(loseform);
		return list;
	}
	private void calcRingValue(String todayDate,
			String orgId,
			ReportInventorySummaryEntity temp) {
		double ringValue;
		ReportInventorySummaryEntity pam = new ReportInventorySummaryEntity();
		pam.setFullOfficeOrgId(orgId);
		Date lastMonth = DateUtils.DateAddMonth(DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate), -1);
		pam.setUpdateTime(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, lastMonth) );
		List<ReportInventorySummaryEntity> lastMonthSummaryList = ReportInventorySummaryQueryService.queryAllReportInventorySummary(pam);
		if(!CollectionUtils.isEmpty(lastMonthSummaryList)){
			ReportInventorySummaryEntity last = lastMonthSummaryList.get(0);
			if(!StringUtils.isEmpty(last.getInstallEquipmentNum())){
				// 进行计算
				Integer lastRing = Integer.valueOf(last.getInstallEquipmentNum());	//上月
				Integer thisRing = Integer.valueOf(temp.getInstallEquipmentNum()); // 本月
				if(lastRing == 0&&thisRing==0){
					temp.setRingGrowth("0");
				}else if(lastRing == 0&&thisRing!=0){
					temp.setRingGrowth("1");
				}else{
					DecimalFormat    df   = new DecimalFormat("#0.00");   
					ringValue = (thisRing-lastRing)*1.00/lastRing;
					temp.setRingGrowth(df.format(ringValue));
				}
			}else{
				check0or1(temp);
			}
		}else{
			check0or1(temp);
		}
	}
	/**
	 * 当上月没有数据时候,判断环比值设0还是设1(本月有值,设1,否则0)
	 * @author cao.weiwei
	 * @date 2017年10月19日 下午3:00:51
	 * @param temp
	 */
	private void check0or1(ReportInventorySummaryEntity temp) {
		if(!StringUtils.isEmpty(temp.getInstallEquipmentNum()) && Integer.valueOf(temp.getInstallEquipmentNum())>0){
			temp.setRingGrowth("1");
		}else{
			temp.setRingGrowth("0");
		}
	}
	private void calcRelativeValue(String todayDate,
			String orgId,
			ReportInventorySummaryEntity temp) {
		double ringValue = 0;;
		ReportInventorySummaryEntity pam = new ReportInventorySummaryEntity();
		pam.setFullOfficeOrgId(orgId);
		Date lastMonth = DateUtils.getDatePlusDay(DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate), -1);
		pam.setUpdateTime(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, lastMonth) );
		List<ReportInventorySummaryEntity> lastMonthSummaryList = ReportInventorySummaryQueryService.queryAllReportInventorySummary(pam);
		if(!CollectionUtils.isEmpty(lastMonthSummaryList)){
			ReportInventorySummaryEntity last = lastMonthSummaryList.get(0);
			if(!StringUtils.isEmpty(last.getInstallEquipmentNum()) && Integer.valueOf(last.getInstallEquipmentNum())>0){
				// 进行计算
				Integer lastRing = Integer.valueOf(last.getInstallEquipmentNum());
				Integer thisRing = Integer.valueOf(temp.getInstallEquipmentNum());
				if(lastRing == 0&&thisRing==0){
					temp.setRelativeGrowth("0");
				}else if(lastRing == 0&&thisRing!=0){
					temp.setRelativeGrowth("1");
				}else{
					DecimalFormat    df   = new DecimalFormat("#0.00");   
					ringValue = (thisRing-lastRing)*1.00/lastRing;
					temp.setRelativeGrowth(df.format(ringValue));
				}
			}else{
				checkRelative01(temp);
			}
		}else{
			
			checkRelative01(temp);
		
		}
	}
	/**
	 *  当上天没有数据时候,判断同比值设0还是设1(本天有值,设1,否则0)
	 * @author cao.weiwei
	 * @date 2017年10月19日 下午3:38:10
	 * @param temp
	 */
	private void checkRelative01(ReportInventorySummaryEntity temp) {
		if(!StringUtils.isEmpty(temp.getInstallEquipmentNum()) && Integer.valueOf(temp.getInstallEquipmentNum())>0){
			temp.setRelativeGrowth("1");
		}else{
			temp.setRelativeGrowth("0");
		}
	}
	
	private OfficeEntity getOfficeEntity(String orgId,List<OrgEntity> orgList){
		OfficeEntity ofe = new OfficeEntity();
		for(OrgEntity o: orgList){
			if(o.getOrgId().equals(orgId)){
				if(o.getOrgType().equals("0")){
					ofe.setBranchOrgId(o.getOrgId());
					ofe.setBranchOrgName(o.getOrgName());
					ofe.setOfficeOrgId(o.getOrgId());
					ofe.setOfficeOrgName(o.getOrgName());
				}else if(o.getOrgType().equals("1")){
					ofe.setBranchOrgId(o.getOrgId());
					ofe.setBranchOrgName(o.getOrgName());
					ofe.setOfficeOrgId(o.getOrgId());
					ofe.setOfficeOrgName(o.getOrgName());
				}else if(o.getOrgType().equals("2")){
					ofe.setBranchOrgId(o.getParentOrgId());
					ofe.setBranchOrgName(o.getParentOrgName());
					ofe.setOfficeOrgId(o.getOrgId());
					ofe.setOfficeOrgName(o.getOrgName());
				}
			}
		}
		return ofe;
	}
	
	private Map<String, ReportInventorySummaryEntity> getSummaryMap(
			List<OrgEntity> orgList) {
		Map<String,ReportInventorySummaryEntity> summaryMap = new HashMap<String,ReportInventorySummaryEntity>();
		for(OrgEntity org: orgList){
			summaryMap.put(org.getOrgId(), new ReportInventorySummaryEntity());
		}
		return summaryMap;
	}
	private Map<String, List<Map<String,Object>>> getOrgMap(
			List<OrgEntity> orgList) {
		Map<String,List<Map<String,Object>>> map = new HashMap<String,List<Map<String,Object>>>();
		for(OrgEntity orgEntity: orgList){
			map.put(orgEntity.getOrgId(), new ArrayList<Map<String,Object>>());
		}
		return map;
	}
	private Map<String, List<InventoryStkFlowEntity>> getOrgMap2(
			List<OrgEntity> orgList) {
		Map<String,List<InventoryStkFlowEntity>> map = new HashMap<String,List<InventoryStkFlowEntity>>();
		for(OrgEntity orgEntity: orgList){
			map.put(orgEntity.getOrgId(), new ArrayList<InventoryStkFlowEntity>());
		}
		return map;
	}
	private void buildUsageData(
			Map<String,ReportInventorySummaryEntity> summaryMap,
			List<OrgEntity> orgList,
			String date) {
		Map<String,List<Map<String,Object>>> orgMap = getOrgMap(orgList);
		UserTask userTask_apply = new UserTask();
		userTask_apply.setWorkflowId(ReportConstant.WORKFLOWID_APPLY_FOR_USAGE);
		List<UserTask> taskList_apply = new ArrayList<UserTask>();
		if(StringUtils.isEmpty(date)){
			taskList_apply = activitiTaskQueryService.queryFinishTaskListByProcess(userTask_apply);
		}else{
			taskList_apply =  activitiTaskQueryService.queryFinishTaskListByProcessDay(userTask_apply,date);
		}
		for(UserTask task: taskList_apply){
			List<Map<String,Object>> mainTableList = dymcformQueryService.queryList(buildQueryUsageTableSql(task.getBusinessNo()));
			if(!CollectionUtils.isEmpty(mainTableList)){
				if(mainTableList.get(0).get("ORG_ID")!=null){
					if(orgMap.get(mainTableList.get(0).get("ORG_ID").toString()) == null){
					}else{
						orgMap.get(mainTableList.get(0).get("ORG_ID").toString()).add(mainTableList.get(0));
					}
					
				}
			}
		}
		
		for(Map.Entry<String, List<Map<String,Object>>> entry: orgMap.entrySet()){
			String orgId = entry.getKey();
			List<Map<String,Object>> list = entry.getValue();
			Integer sumDevelop = 0;
			Integer sumSale = 0;
			Integer sumShow = 0;
			Integer sumTest = 0;
			Integer sumOther = 0;
			for(Map<String,Object> mainTable: list){
				if(mainTable.get("OUT_TYPE")!=null){
					String out_type = mainTable.get("OUT_TYPE").toString();
					Integer sumsubatble = queryUsageEquipmentSum(mainTable);
					if(out_type.equals("16")){//开发出库
						sumDevelop = sumDevelop + sumsubatble;
					}else if(out_type.equals("17")){//销售出库
						sumSale = sumSale + sumsubatble;
					}else if(out_type.equals("18")){//展示出库
						sumShow = sumShow + sumsubatble;
					}else if(out_type.equals("19")){ //测试出库
						sumTest = sumTest + sumsubatble;
					}else{
						sumOther = sumOther+ sumsubatble;
					}
				}
			}
			
			summaryMap.get(orgId).setSumDevelop(sumDevelop.toString());
			summaryMap.get(orgId).setSumSale(sumSale.toString());
			summaryMap.get(orgId).setSumShow(sumShow.toString());
			summaryMap.get(orgId).setSumTest(sumTest.toString());
			summaryMap.get(orgId).setSumOther(sumOther.toString());
			
		}
		
		
	}
	private void buildScrapData(
			Map<String,ReportInventorySummaryEntity> summaryMap,
			Map<String,ReportInventorySummaryEntity> scrapSummaryMap,
			List<OrgEntity> orgList,
			String date) {
		Map<String,List<Map<String,Object>>> orgMap = getOrgMap(orgList);
		UserTask userTask_scrap = new UserTask();
		userTask_scrap.setWorkflowId(ReportConstant.WORKFLOWID_EQUIPMENT_SCRAP);
		List<UserTask> taskList_scrap = new ArrayList<UserTask>();
		if(StringUtils.isEmpty(date)){
			taskList_scrap = activitiTaskQueryService.queryFinishTaskListByProcess(userTask_scrap);
		}else{
			taskList_scrap = activitiTaskQueryService.queryFinishTaskListByProcessDay(userTask_scrap,date);
		}
		
		Integer sumScrap = 0;
		for(UserTask task: taskList_scrap){
			List<Map<String,Object>> mainTableList = dymcformQueryService.queryList(buildQueryScrapTableSql(task.getBusinessNo()));
			if(!CollectionUtils.isEmpty(mainTableList)){
				if(mainTableList.get(0).get("ORG_ID")!=null){
					orgMap.get(mainTableList.get(0).get("ORG_ID").toString()).add(mainTableList.get(0));
				}
			}
		}
		
		for(Map.Entry<String, List<Map<String,Object>>> entry: orgMap.entrySet()){
			String orgId = entry.getKey();
			List<Map<String,Object>> list = entry.getValue();
			for(Map<String,Object> mainTable: list){
				sumScrap = sumScrap+ queryScrapEquipmentSum(mainTable);
			}
			if(!StringUtils.isEmpty(scrapSummaryMap.get(orgId).getSumScrap())){
				Integer temp = Integer.valueOf(scrapSummaryMap.get(orgId).getSumScrap());
				sumScrap = sumScrap+temp;
				summaryMap.get(orgId).setSumScrap(sumScrap.toString());
			}else{
				summaryMap.get(orgId).setSumScrap(sumScrap.toString());
			}
			
		}
		
	}
	
	private Map<String,ReportInventorySummaryEntity> buildRepairData(
			Map<String,ReportInventorySummaryEntity> summaryMap,List<OrgEntity> orgList,
			String date) {
		Map<String,ReportInventorySummaryEntity> scrapSummaryMap = getSummaryMap(orgList); // 存放维修流程中的报废
		Map<String,List<Map<String,Object>> > orgMap = getOrgMap(orgList);
		UserTask userTask_repair = new UserTask();
		userTask_repair.setWorkflowId(ReportConstant.DYMCFORM_TABLE_EQUIPMENT_SERVICE);
		List<UserTask> taskList1 = new ArrayList<UserTask>();
		if(StringUtils.isEmpty(date)){
			taskList1 = activitiTaskQueryService.queryFinishTaskListByProcess(userTask_repair);
		}else{
			taskList1 = activitiTaskQueryService.queryFinishTaskListByProcessDay(userTask_repair, date);
		}
		
		for(UserTask task: taskList1){
			List<Map<String,Object>> mainTableList = dymcformQueryService.queryList(buildQueryRepairTableSql(task.getBusinessNo()));
			if(!CollectionUtils.isEmpty(mainTableList)){
				if(mainTableList.get(0).get("ORG_ID")!=null) {
					orgMap.get(mainTableList.get(0).get("ORG_ID").toString()).add(mainTableList.get(0));
				}
			}
		}
		
		for(Map.Entry<String, List<Map<String,Object>>> entry: orgMap.entrySet()){
			Integer sumRepair = 0;
			Integer sumScarp = 0;
			List<Map<String,Object>> list = entry.getValue();
			for(Map<String,Object> mainTable: list){
				sumRepair = sumRepair+ queryCalEquipmentSum(mainTable);
				sumScarp = sumRepair+ queryServiceEquipmentSum(mainTable);
			}
			summaryMap.get(entry.getKey()).setSumRepair(sumRepair.toString());	
			scrapSummaryMap.get(entry.getKey()).setSumRepair(sumScarp.toString());
		}
		
		return scrapSummaryMap;
	}
	private void buildAccessStorage(
			Map<String,ReportInventorySummaryEntity> summaryMap,List<OrgEntity> orgList,String date) {
		Map<String,List<InventoryStkFlowEntity> > orgMapIn = getOrgMap2(orgList);
		Map<String,List<InventoryStkFlowEntity> > orgMapOut = getOrgMap2(orgList);
		InventoryStkFlowEntity inventoryStkFlowEntity = new InventoryStkFlowEntity();
		if(StringUtils.isEmpty(date)){
			String yesterDay = DateUtils.DateToString(DateUtils.TIMEPATTERN, DateUtils.getDatePlusDay(new Date(), -1));
			inventoryStkFlowEntity.setLastUpdateTimeEnd(DateUtils.getCurrentTime().substring(0,10));
			inventoryStkFlowEntity.setLastUpdateTimeStart(yesterDay);
			inventoryStkFlowEntity.setIsDel(SysConstant.FAIL);
		}else{
			Date theDate = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, date);
			Date thDateAfter = DateUtils.getDatePlusDay(theDate, 1);
			String theDateStr = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD,theDate);
			String theDateAfterStr = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD,thDateAfter);
			inventoryStkFlowEntity.setLastUpdateTimeEnd(theDateAfterStr);
			inventoryStkFlowEntity.setLastUpdateTimeStart(theDateStr);
			inventoryStkFlowEntity.setIsDel(SysConstant.FAIL);
		}
	
		List<InventoryStkFlowEntity> inventoryStkFlowEntityListAll = inventoryStkFlowQueryService.queryAllInventoryStkFlow(inventoryStkFlowEntity);
		for(InventoryStkFlowEntity item: inventoryStkFlowEntityListAll){
			String orgId = item.getOrgId();
			if(SysConstant.SUCCESS.equals(item.getIsOut())){
				orgMapOut.get(orgId).add(item); // 出库
			}else if(SysConstant.FAIL.equals(item.getIsOut())){
				orgMapIn.get(orgId).add(item); // 入库
			}
		}
		for(Map.Entry<String, List<InventoryStkFlowEntity>> entry: orgMapIn.entrySet()){
			String orgId = entry.getKey();
			List<InventoryStkFlowEntity>  list = entry.getValue();
			summaryMap.get(orgId).setSumIn(list.size()+"");
		}
		for(Map.Entry<String, List<InventoryStkFlowEntity>> entry: orgMapOut.entrySet()){
			String orgId = entry.getKey();
			List<InventoryStkFlowEntity>  list = entry.getValue();
			summaryMap.get(orgId).setSumOut(list.size()+"");
		}
	}
	private void buildInstallData(
			Map<String,ReportInventorySummaryEntity> summaryMap,List<OrgEntity> orgList,String date) {
		Map<String,List<Map<String,Object>> > orgMap = getOrgMap(orgList);
		UserTask userTask = new UserTask();
		userTask.setWorkflowId(ReportConstant.WORKFLOWID_INSTALL);
		List<UserTask> taskList = new ArrayList<UserTask>();
		if(StringUtils.isEmpty(date)){
			taskList = activitiTaskQueryService.queryFinishTaskListByProcess(userTask);
		}else{
			taskList = activitiTaskQueryService.queryFinishTaskListByProcessDay(userTask,date);
		}
		
		for(UserTask task: taskList){
			List<Map<String,Object>> mainTableList = dymcformQueryService.queryList(buildQueryInstallTableSql(task.getBusinessNo()));
			if(!CollectionUtils.isEmpty(mainTableList)){
				if(mainTableList.get(0).get("ORG_ID")!=null ){
					String orgId = mainTableList.get(0).get("ORG_ID").toString();
					if(orgMap.get(orgId)==null){
						logger.debug(orgId);
					}else{
						orgMap.get(orgId).add(mainTableList.get(0));
					}
					
				}
			}
		}
		
		buildInstallSumData(summaryMap, orgMap);
	}
	/**
	 * 计算安装店铺数,安装设备数
	 * @author cao.weiwei
	 * @date 2017年7月6日 下午4:30:52
	 * @param summaryMap
	 * @param orgMap
	 */
	private void buildInstallSumData(Map<String, ReportInventorySummaryEntity> summaryMap,
			Map<String, List<Map<String, Object>>> orgMap) {
		for(Map.Entry<String, List<Map<String,Object>>> orgObject: orgMap.entrySet()){
			List<Map<String,Object>> mainTableList = orgObject.getValue();
			Map<String,String> shopIdMap = new HashMap<String,String >();
			Integer equipmentSum = 0;
			for(Map<String,Object> mainTable: mainTableList){
				List<Map<String,Object>> installTableList = dymcformQueryService.queryList(buildQuerySubTableSql(mainTable.get("ID").toString(),ReportConstant.DYMCFORM_SUBTABLE_INSTALL_DETAIL));
				for(Map<String,Object> item: installTableList){
					equipmentSum += Integer.parseInt(item.get("EQ_NUM").toString());
				}
				shopIdMap.put(mainTable.get("SHOP_ID").toString(), mainTable.get("SHOP_NAME").toString());
			}
			summaryMap.get(orgObject.getKey()).setInstallEquipmentNum(equipmentSum.toString());
			summaryMap.get(orgObject.getKey()).setInstallShopNum(shopIdMap.entrySet().size()+"");
		}
	}
	private Integer queryUsageEquipmentSum( Map<String, Object> mainTable) {
		Integer sum = 0;
		List<Map<String,Object>> serviceTableList = dymcformQueryService.queryList(buildQuerySubTableSql(mainTable.get("ID").toString(),ReportConstant.DYMCFORM_SUBTABLE_APPLY_FOR_USAGE_LIST));
		if(!CollectionUtils.isEmpty(serviceTableList)){
			for(Map<String,Object> item: serviceTableList){
				sum = sum+Integer.parseInt(item.get("EQ_NUM").toString());
			}
		}
		return sum;
	}
	private Integer queryServiceEquipmentSum( Map<String, Object> mainTable) {
		Integer sum = 0;
		List<Map<String,Object>> serviceTableList = dymcformQueryService.queryList(buildQuerySubTableSql(mainTable.get("ID").toString(),ReportConstant.DYMCFORM_SUBTABLE_EQUIPMENT_SERVICE_SERVICE));
		if(!CollectionUtils.isEmpty(serviceTableList)){
			for(Map<String,Object> item: serviceTableList){
				sum = sum+Integer.parseInt(item.get("EQ_NUM").toString());
			}
		}
		return sum;
	}
	private Integer queryScrapEquipmentSum( Map<String, Object> mainTable) {
		Integer sum = 0;
		List<Map<String,Object>> callTableList = dymcformQueryService.queryList(buildQuerySubTableSql(mainTable.get("ID").toString(),ReportConstant.DYMCFORM_SUBTABLE_EQUIPMENT_SCRAP_LIST));
		if(!CollectionUtils.isEmpty(callTableList)){
			for(Map<String,Object> item: callTableList){
				sum = sum+Integer.parseInt(item.get("EQ_NUM").toString());
			}
		}
		return sum;
	}
	private Integer queryCalEquipmentSum( Map<String, Object> mainTable) {
		Integer sum = 0;
		List<Map<String,Object>> callTableList = dymcformQueryService.queryList(buildQuerySubTableSql(mainTable.get("ID").toString(),ReportConstant.DYMCFORM_SUBTABLE_EQUIPMENT_SERVICE_CALL));
		if(!CollectionUtils.isEmpty(callTableList)){
			for(Map<String,Object> item: callTableList){
				sum = sum+Integer.parseInt(item.get("EQ_NUM").toString());
			}
		}
		return sum;
	}
	private String buildQuerySubTableSql(String mainTableId,String subTableName){
		StringBuffer sb = new StringBuffer();
		sb.append(" SELECT EQ_TYPE_ID,EQ_TYPE_NAME,EQ_NUM ");
		sb.append(" FROM ").append(subTableName);
		sb.append(" WHERE ");
		sb.append(" MAIN_TABLE_ID ='").append(mainTableId).append("'");
		sb.append(" AND IS_DEL = '0';");
		return sb.toString();
	}
	private String buildQueryUsageTableSql(String wo_no){
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT ID,WO_NO,OUT_TYPE,STORAGE_ID,STORAGE_NAME,ORG_ID,CREATE_USER,CREATER,CREATE_TIME ");
		sb.append("FROM ").append(ReportConstant.DYMCFORM_TABLE_APPLY_FOR_USAGE).append(" where ");
		sb.append("WO_NO ='").append(wo_no).append("'  and CHECK_RESULT='1' ");
		sb.append(";");
		return sb.toString();
	}
	private String buildQueryRepairTableSql(String wo_no){
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT ID,WO_NO,SHOP_ID,SHOP_NAME,ORG_ID,CREATE_USER,CREATER,CREATE_TIME ");
		sb.append("FROM ").append(ReportConstant.DYMCFORM_TABLE_EQUIPMENT_SERVICE).append(" where ");
		sb.append("WO_NO ='").append(wo_no).append("' and CHECK_RESULT='1' and CONFIRM_RESULT='1' ");
		sb.append(";");
		return sb.toString();
	}
	private String buildQueryScrapTableSql(String wo_no){
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT ID,WO_NO,APPLY_PEOPLE,STORAGE_ID,STORAGE_NAME,STORAGE_ADDR,STORAGE_ADDR_ID,ORG_ID,CREATE_USER,CREATE_TIME ");
		sb.append("FROM ").append(ReportConstant.DYMCFORM_TABLE_EQUIPMENT_SCRAP).append(" where ");
		sb.append("WO_NO ='").append(wo_no).append("' and CHECK_RESULT='1' ");
		sb.append(";");
		return sb.toString();
	}
	private String buildQueryInstallTableSql(String wo_no){
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT ID,WO_NO,ORG_ID,CREATE_USER,CREATER,CREATE_TIME,SHOP_ID, SHOP_NAME ");
		sb.append("FROM ").append(ReportConstant.DYMCFORM_TABLE_INSTALL).append(" where ");
		sb.append("WO_NO ='").append(wo_no).append("' and INSTALL_RESULT='1' and CHECK_RESULT='1' ");
		sb.append(";");
		return sb.toString();
	}
	public ResponseEntity testTask(String date) {
		if(StringUtils.isEmpty(date)){
			return scanForm(null);
		}else{
			return scanForm(date);
		}
		
	}
	
}

